package com.angel.web.app;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.angel.core.Constants;
import com.angel.core.payUtil.OrderInfoUtil2_0;
import com.angel.core.payUtil.WeiXinPay;
import com.angel.core.util.JsonUtil;
import com.angel.core.util.PropertyConfUtil;
import com.angel.core.util.XmlUtil;

/** 
* @author 作者姓名  cheng
* @version 
* 创建时间：2016年11月28日 下午3:12:55 
* 类说明 
*/
@Controller
@RequestMapping("app/pay")
public class PayController {

	@ResponseBody
	@RequestMapping(value = "zfbSign", produces = "application/json; charset=utf-8")
	public String getInfo(){
		String appid = PropertyConfUtil.getContextProperty(Constants.ZFB_APPID);
		String rsa = PropertyConfUtil.getContextProperty(Constants.ZFB_PAY_KEY);
		Map<String, String> params = OrderInfoUtil2_0.buildOrderParamMap(appid);
		String orderParam = OrderInfoUtil2_0.buildOrderParam(params);
		String sign = OrderInfoUtil2_0.getSign(params, rsa);
		String orderInfo = orderParam + "&" + sign;
		return orderInfo;
	}
	
	@ResponseBody
	@RequestMapping(value = "wxPay", produces = "application/json; charset=utf-8")
	public String wxPay(){
		Map map = new HashMap<>();
		try {
			map = XmlUtil.xmltoMap(WeiXinPay.submitOrder(0.01, "11", "120.0.0.1"));
			map.put("timestamp", System.currentTimeMillis());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.err.println(JsonUtil.toJson(map));
		return JsonUtil.toJson(map);
	}
}
